package com.xmall.sys.service.impl.other;

import com.xmall.msg.queue.CommonModule;
import com.xmall.define.dto.sys.DictDto;
import com.xmall.msg.base.MsgSourceType;
import com.xmall.msg.entity.dict.DictUpdateMsg;
import com.xmall.sys.service.other.IMsgService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MsgServiceImpl implements IMsgService {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 更新字典消息
     */
    @Override
    public void sendUpdateDictMsg(DictDto dictDto) {
        DictUpdateMsg msg = new DictUpdateMsg().build(MsgSourceType.SYS, CommonModule.CommonExchange.DICT_FANOUT_EXCHANGE, "").dictDto(dictDto);
        rabbitTemplate.convertAndSend(CommonModule.CommonExchange.DICT_FANOUT_EXCHANGE, "", msg, new CorrelationData(msg.getCorrelationKey()));
    }
}
